package com.konne.nightmare.FastPublicOpinion.utils;

import com.tencent.mmkv.MMKV;

public class MMKVUtils {

    private volatile static MMKV mmkv;

    private static MMKV getInstance(){
        if (mmkv == null){
            synchronized (MMKV.class){
                if (mmkv == null){
                    mmkv = MMKV.defaultMMKV();
                }
            }
        }
        return mmkv;
    }

    public static String getMMKVString(String key) {
        return getInstance().decodeString(key);
    }

    public static void setMMKVString(String key,String value) {
        getInstance().encode(key,value);
    }

    public static boolean getMMKVBoolean(String key) {
        return getInstance().decodeBool(key);
    }

    public static void setMMKVBoolean(String key,boolean value) {
        getInstance().encode(key,value);
    }

    public static void setMMKVInteger(String key,int value) {
        getInstance().encode(key,value);
    }

    public static int getMMKVInteger(String key) {
        return getInstance().decodeInt(key);
    }

    public static void setMMKVFloat(String key, float value) {
        getInstance().encode(key,value);
    }

    public static float getMMKVFloat(String key) {
        return getInstance().decodeFloat(key);
    }

    public static void setMMKVLong(String key, long value) {
        getInstance().encode(key,value);
    }

    public static long getMMKVLong(String key) {
        return getInstance().decodeLong(key);
    }

    public static void clearValueForKey(String key){
        getInstance().removeValueForKey(key);
    }

    public static void clearValuesForKeys(String[] keys){
        getInstance().removeValuesForKeys(keys);
    }

    public static void clearAllMMKV() {
        getInstance().clearAll();
    }

}
